<?php
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
$tabs=array(
	array('op'=>'list','title'=>'订单列表'),
);
set_html('tabs',$tabs);
if($_RQ['op']=='list'){
	
	$pindex = max(1, intval($_SESSION['page']));
	$psize = 15;
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if($_RQ['mid']){
		$params['mid']=intval($_RQ['mid']);
		$return['params']['mid']=$_RQ['mid'];
	}
	if($_RQ['ordersn']){
		$params['ordersn']=intval($_RQ['ordersn']);
		$return['params']['ordersn']=$_RQ['ordersn'];
	}
	if(isset($_RQ['status'])){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=$_RQ['status'];
	}
	$psize=20;
	$pindex=intval($_RQ['page'])?:1;
	$parameter=array(
		'params'=>$params,
		'limit'=>array($pindex,$psize),
		'orderby'=>'id desc',
	);
	$list=$this->get_list('order',$parameter,$total);
	if($list){
		foreach($list as &$item){
			$item['member']=cfc('core')->member_show($item['mid']);
			//$item['detail']='/commission/list/ordersn='.$item['ordersn'];
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'list'=>array('data'=>'list','edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'member','title'=>'会员信息','type'=>'member'),
			array('name'=>'ordersn','title'=>'订单号','type'=>'string'),
			array('name'=>'price','title'=>'订单金额','type'=>'string'),
			array('name'=>'expressid','title'=>'快递公司','type'=>'radio','options'=>'expressid'),
			array('name'=>'expresssn','title'=>'快递单号','type'=>'string'),
			array('name'=>'createtime','title'=>'创建时间','type'=>'time'),
		),'action'=>array(
			//array('type'=>'href','name'=>'detail','title'=>'佣金明细'),
			array('op'=>'fa','title'=>'发货','type'=>'modal','show'=>array('status'=>1)),
			
		)),
		'search'=>array(
			array('type'=>'string','name'=>'ordersn','title'=>'订单号','width'=>'15'),
			array('type'=>'select','name'=>'status','title'=>'订单状态','width'=>'15','options'=>'status_select'),
		),
	);
	$return['htmls']=$htmls;
	
	$return['status']=array('0'=>'待支付','1'=>'待发货','2'=>'已发货','3'=>'已收货','4'=>'已完成','5'=>'已关闭');
	//$return['status_select']=array('0'=>array('id=>0','title'=>'待支付'),'1'=>'待发货','2'=>'已发货','3'=>'已收货','4'=>'已完成','5'=>'已关闭');
	$return['status_select']=array('0'=>array('id'=>'0','title'=>'待支付'),'1'=>array('id'=>'1','title'=>'待发货'),'2'=>array('id'=>'2','title'=>'已发货'),'3'=>array('id'=>'3','title'=>'已收货'),'4'=>array('id'=>'4','title'=>'已完成'),'5'=>array('id'=>'5','title'=>'已关闭'));
	$return['expressid']=array(
		'1' => '顺丰快递',
		'2'=> '申通快递',
		'3'=> '韵达快运',
		'4'=> '天天快递',
		'5'=> '圆通速递',
		'6' => '中通速递',
		'7'=> 'ems快递',
		'8'=> '汇通快运',
		'9'=> '其它快递'
	); 
	exi($return);
}
if($_RQ['op']=='fa'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$id=intval($post['id']);
		if(!$id){
			exi('参数错误！','error');
		}
			if(!$post['expressid'] || !$post['expresssn']){
				exi('请填写快递信息','error');
			}
			$data=array('expressid'=>$post['expressid'],'expresssn'=>$post['expresssn'],'status'=>2);
			pdo_update('jy_weishop_cutprice_order',$data,array('id'=>$id));
			exi('已发货！','','//list/status=2');
	}
	$id=intval($_RQ['id']);
	$item=$this->pdo_get('order',array('id'=>$id),array('id'));
	
	$htmls=array(
		'type'=>'edit',
		'desc'=>'订单发货',
	);
	
	$htmls['edit']=array(
		array('type'=>'select','title'=>'快递公司','name'=>'expressid','options'=>'expressid','option_title'=>'name'),
		array('type'=>'string','title'=>'快递单号','name'=>'expresssn'),
	);
	$return['expressid']=array(
		'1' => Array ( 'id'=> 1, 'name' => '顺丰快递' ),
		'2' => Array ( 'id' => 2, 'name' => '申通快递' ),
		'3' => Array ( 'id' => 3,'name' => '韵达快运' ),
		'4' => Array ('id'=>4,'name' => '天天快递' ),
		'5' => Array ( 'id' => 5, 'name' => '圆通速递' ) ,
		'6' => Array ( 'id' => 6,'name' => '中通速递' ) ,
		'7' => Array ( 'id' => 7 ,'name' => 'ems快递' ),
		'8' => Array ( 'id' => 8, 'name' => '汇通快运' ),
		'9' => Array ( 'id' => 9, 'name' => '其它快递' )
	); 

	$return['htmls']=$htmls;
	$return['item']=$item;
	exi($return);
}
?>